Hello,
I posted this on another forum, and I figure I would try here as well.
I have a rather straightforward challenge and I need a little help. Let me preface that I am not a very experienced kernel module developer, but I have read through some of the basic tutorials and examples. I also have a fair amount of C/C++ experience, so I am not a complete novice in those regards.
The challenge is to count the contents of each /proc/[pid]/fd directory from a kernel module. Basically, counting the number of open file descriptors for each process. Now, I can get each pid using the following segment:
Code:
struct task_struct *task;
for_each_process(task)
{
task->pid
}
From that, I can construct the absolute pathname /proc/[pid]/fd for each process, and use the path_loookup() method to begin further analysis of the directory. After that, I am struggling on how to traverse/count the contents of the /fd directories. I can get the struct dentry object for the directory using struct dentry *lookup_create(), but I don't have a good enough understanding of using the struct dentry or struct inode types to proceed after that.
Any suggestions on how to properly proceed or recommendations on how I can accomplish this task. I know there are easy ways to do this from user space; however, that option is not available. The challenge is to do it from kernel space.
I am developing this for kernel distro 2.6.31-14-generic on Ubuntu 9.10 Karmic Koala.
Thank you for any help.
*************************************
Updated later with the follow-up post
*************************************
I have been doing some more looking around and have yet to figure out anything definitive.
However, I did discover the functions proc_root_readdir() and others located in linux/fs/proc/root.c. Is this headed in the right direction or am I heading down the wrong "Rabbit Hole"?
Another thought based on other examples and calls I have seen: should I try to get the "struct file" object for a /proc/[pid]/fd directory and then try to count the file offsets from the directory (ignoring the offsets 1 and 2 for "." and ".." respectively)?
Once again, I apologize if I am way off base. If so, please provide some feedback to put me down the proper path.